package com.pb.infra.auth.controller;

import com.pb.infra.oth.entity.common.Page;
import com.pb.infra.oth.entity.common.Result;
import com.pb.infra.auth.entity.custom.PriviPasswdCustom;
import com.pb.infra.auth.entity.pbsys.PriviPasswdPolicy;
import com.pb.infra.auth.service.PriviPasswdPolicyService;
import com.pb.infra.oth.util.Constant;
import com.pb.infra.oth.util.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 法人密码策略管理
 *
 * @author liudebao
 * @date 2020/1/1
 */
@Slf4j
@RestController
@RequestMapping("v1/system/corpPasswd")
public class PriviPasswdPolicyController {

    /**
     * 日志操作表
     */
    private static final String TABLE_NAME = "PRIVI_PASSWD_POLICY";

    /**
     * 日志操作功能名
     */
    private static final String OPERATION_MENU = "法人密码策略管理";

    /**
     * 业务逻辑对象
     */
    @Resource
    private PriviPasswdPolicyService priviPasswdPolicyService;

    /**
     * 查询法人密码策略
     * @param paramMap 请求参数
     * @param page
     * @return Result 返回数据
     */
    @GetMapping("select")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result select(@RequestParam Map<String, Object> paramMap, Page page, HttpServletRequest request) {
        return priviPasswdPolicyService.select(paramMap,page,request);
    }

    /**
     * 新建法人密码策略
     *
     * @param priviPasswdPolicy 请求参数
     * @return Result 返回数据
     */
    @PostMapping("insert")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.ADD, menuName = OPERATION_MENU)
    public Result insert(PriviPasswdPolicy priviPasswdPolicy, HttpServletRequest request) {
        priviPasswdPolicyService.insert(priviPasswdPolicy, request);
        return Result.OK_EMPTY;
    }


    /**
     * 修改法人密码策略
     *
     * @param priviPasswdPolicy 请求参数
     * @return Result 返回数据
     */
    @PostMapping("update")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.MOD, menuName = OPERATION_MENU)
    public Result update(PriviPasswdCustom priviPasswdPolicy, HttpServletRequest request) {
        priviPasswdPolicyService.update(priviPasswdPolicy, request);
        return Result.OK_EMPTY;
    }

    /**
     * 删除法人密码策略
     *
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @PostMapping("delete")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.DEL, menuName = OPERATION_MENU)
    public Result delete(@RequestBody List<String> paramMap) {
        return priviPasswdPolicyService.delete(paramMap);
    }

    /**
     *查询所有系统密码策略
     * @return Result 返回数据
     */
    @GetMapping("selAllPass")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result selAllPass() {
        return priviPasswdPolicyService.selAllPass();
    }

}
